Skip to content

[react-devtools-facade] 3/ implement profiler tools #36598

Open
hoxyq wants to merge 5 commits into
mainfrom
rdt-facade-3-profiler
Open

[react-devtools-facade] 3/ implement profiler tools #36598
hoxyq wants to merge 5 commits into
mainfrom
rdt-facade-3-profiler

Conversation

@hoxyq

@hoxyq hoxyq commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Stacked on #36597, see this commit.

Adds the profiler building blocks to createTools — per-commit render timing on top of the component-tree tools from commit 2.

Tools

  • startProfiling(name?){status: 'started', trace}. Begins a session that records timing on every commit. Errors if a session is already active.
  • stopProfiling(){status: 'stopped', trace, commits} (commit count). Errors if no session is active.
  • getTraceOverview(traceName) → one row per commit: {commit, committedAt, renderDuration, layoutDuration, passiveDuration, componentsChanged}.
  • getCommitReport(traceName, commitIndex) → one commit's detail:
    {committedAt, priority, renderDuration, layoutDuration, passiveDuration, components}, where components is {label, name, type, actualDuration, selfDuration} sorted by actualDuration descending.

Durations are in milliseconds, or null when the build does not collect profiler
timing. passiveDuration is attributed per root via the hook's post-commit pass.

@meta-cla meta-cla Bot added the CLA Signed label Jun 2, 2026
@hoxyq hoxyq changed the title [react-devtools-facade] implement profiler tools [react-devtools-facade] 3/ implement profiler tools Jun 3, 2026
@hoxyq hoxyq force-pushed the rdt-facade-3-profiler branch from f4e0f7a to 873639a Compare June 3, 2026 17:22
@hoxyq hoxyq marked this pull request as ready for review June 3, 2026 17:32
@hoxyq hoxyq requested review from eps1lon and jackpope June 10, 2026 05:17
@hoxyq hoxyq force-pushed the rdt-facade-3-profiler branch from 873639a to 15efdb5 Compare June 10, 2026 05:35
hoxyq added 5 commits June 10, 2026 08:42
Introduces react-devtools-facade, a private, source-only library of building
blocks for querying React runtime state.

This first commit adds installFacade(target): it installs only
__REACT_DEVTOOLS_GLOBAL_HOOK__ (the global React looks for at init) and returns
a Facade handle {hook, fiberRoots, rendererInternals, profilingState}. It
installs no tool globals — integrators (e.g. a chrome-devtools-mcp package)
compose the Facade into tools and decide what to expose.

Its tests rely on the devtools build/dev setup, so the package is excluded from
the general test runners and runs only under the build-devtools jest project —
matching react-devtools-shared and react-devtools-extensions.

Tool building blocks and a createTools(facade) assembler land in follow-ups.
inspectHooks/inspectHooksOfFiber default currentDispatcher to
ReactSharedInternals, and shared/ReactSharedInternals imports React — so bundling
them drags all of React in, even for callers that always pass the renderer's
injected dispatcher (e.g. react-devtools-facade).

Extract the shared logic into private inspectHooksImpl / inspectHooksOfFiberImpl,
which require an explicit dispatcher and never reference ReactSharedInternals.
inspectHooks and inspectHooksOfFiber keep their existing behavior as thin
wrappers that supply the ReactSharedInternals default. Add exported
inspectHooksWithoutDefaultDispatcher and
inspectHooksOfFiberWithoutDefaultDispatcher that delegate to the Impls directly,
so a bundle importing only them references no React.
Move getDispatcherRef out of backend/fiber/renderer.js into
backend/shared/DevToolsReactDispatcher.js and import it back. This lets other
consumers (e.g. react-devtools-facade) reuse the renderer-dispatcher adapter
without importing the whole renderer module.
Adds the component-tree building blocks and the createTools assembler.

createTools(facade) reads the facade's tracked state and returns the tools
object (no globals): getComponentTree, getComponentByLabel, findComponents,
getComponentSource, getOwnersStack, getOwnersBranch. Tools return typed plain
JavaScript values (see DevToolsFacadeTreeTools); serialization is left to the
integration package.

getComponentByLabel includes the component's props and, for function
components, its inspected hooks tree, obtained via react-debug-tools'
inspectHooksOfFiberWithoutDefaultDispatcher with the renderer's injected
dispatcher (normalized by getDispatcherRef), so the facade never falls back to
(and bundles) React's shared internals.
Adds the profiler building blocks to createTools: startProfiling,
stopProfiling, getTraceOverview, getCommitReport. A profiling session records
per-commit render timing (via the hook's onCommit/onPostCommit, wired in the
scaffold commit) and reports per-component actual/self durations, sorted
descending. Tools return typed plain JavaScript values; serialization is left
to the integration package.
@hoxyq hoxyq force-pushed the rdt-facade-3-profiler branch from 15efdb5 to 4b519bd Compare June 10, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant